package com.qst0916_3.service.impl;

import com.qst0916_3.dao.UserDao;
import com.qst0916_3.entity.User;
import com.qst0916_3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public int addUser(User u1, User u2) {
        int result=0;
        try {
            result = userDao.insert(u1);
            result += userDao.insert(u2);
            System.out.println("事务完成");
        }catch (Exception e){
            result=0;
            System.out.println("事务回滚" );
            e.printStackTrace();
            throw new  RuntimeException() ;
        }
        return result;
    }
}
